package com.mesd.killer.web;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mesd.framework.util.DateUtil;
import com.mesd.framework.util.StringUtil;
import com.mesd.framework.web.BaseController;
import com.mesd.killer.constrant.ICompanyName;
import com.mesd.killer.filter.CompanyBean;
import com.mesd.killer.filter.SearchBean;
import com.mesd.killer.importer.GameDetailReader;
import com.mesd.killer.model.GameDetail;
import com.mesd.killer.model.GameResult;
import com.mesd.killer.service.KillerService;

@Controller
@RequestMapping("/killerWeb.sp")
public class KillerWebController extends BaseController
{

	private static final double PERCENT = 0.8;

	@Autowired
	private KillerService killerService;

	@RequestMapping(params = "method=todayGame")
	public @ResponseBody
	String todayGame()
	{
		Calendar startC = Calendar.getInstance();
		startC.set(
			2012, 5, 20);
		Date start = startC.getTime();

		Calendar endC = Calendar.getInstance();
		endC.set(
			2012, 6, 1);
		Date end = endC.getTime();
		List<GameResult> result = killerService.searchGameResult(
			start, end);
		if (result == null)
			return null;
		StringBuffer sb = new StringBuffer();
		return sb.toString();
	}

	@RequestMapping(params = "method=todayGames")
	public @ResponseBody
	String todayGames()
	{
		List<GameResult> result = killerService.searchTodayGameResult();
		StringBuffer sb = new StringBuffer();
		if (result == null)
			return null;
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("比赛日期");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("联赛");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("比赛编号");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("半场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("全场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("盘口结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("分析");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("凯勒分析结果");
		sb.append("</td>");
		sb.append("</tr>");
		for (int i = 0; i < result.size(); i++)
		{
			GameResult gameResult = result.get(i);
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(gameResult.getGameTime().toLocaleString());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getLeagueName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getHostTeam());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getVisitTeam());
			sb.append("</td>");
			sb.append("<td><a href='analysis.jsp?gameID=" + gameResult.getGameId() + "'>");
			sb.append(gameResult.getGameId());
			sb.append("</a></td>");
			sb.append("<td>");
			sb.append(gameResult.getHalfScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getFullScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getPankouResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getDaxiaoResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("<input type='button' value='分析' onclick='analysis(" + gameResult.getGameId()
				+ ")'");
			sb.append("</td>");
			sb.append("<td id=killerResult" + gameResult.getGameId() + ">");
			sb.append("</td>");
			sb.append("</tr>");
		}
		return sb.toString();
	}

	@RequestMapping(params = "method=analysisAll")
	public @ResponseBody
	String analysisAll(HttpServletRequest request)
	{
		List<GameResult> result = killerService.searchTodayGameResult();
		StringBuffer sb = new StringBuffer();
		if (result == null)
			return null;
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("比赛日期");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("联赛");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("比赛编号");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("半场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("全场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("盘口结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("分析");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("凯勒分析结果");
		sb.append("</td>");
		sb.append("</tr>");
		for (int i = 0; i < result.size(); i++)
		{
			GameResult gameResult = result.get(i);
			long gameId = gameResult.getGameId();
			SearchBean bean = new SearchBean();
			String shuiweiOffset = request.getParameter("shuiweiOffset");
			String daxiaoOffset = request.getParameter("daxiaoOffset");
			String hasDaxiao = request.getParameter("hasDaxiao");
			bean.setHasDaxiao(Integer.parseInt(hasDaxiao));
			bean.setBigOffset(Float.parseFloat(daxiaoOffset));
			bean.setShuiweiOffset(Float.parseFloat(shuiweiOffset));
			bean.setGameId(gameId);
			List<GameResult> analysisResult = killerService.SearchGameResult(bean);
			String killerResult = killerService.getAnalysisResult(analysisResult, false);
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(gameResult.getGameTime().toLocaleString());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getLeagueName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getHostTeam());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getVisitTeam());
			sb.append("</td>");
			sb.append("<td><a href='analysis.jsp?gameID=" + gameResult.getGameId() + "'>");
			sb.append(gameResult.getGameId());
			sb.append("</a></td>");
			sb.append("<td>");
			sb.append(gameResult.getHalfScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getFullScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getPankouResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getDaxiaoResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("<input type='button' value='分析' onclick='analysis(" + gameResult.getGameId()
				+ ")'");
			sb.append("</td>");
			sb.append("<td>");
			sb.append(killerResult);
			sb.append("</td>");
			sb.append("</tr>");
		}
		return sb.toString();
	}

	@RequestMapping(params = "method=search")
	public @ResponseBody
	String search(HttpServletRequest request)
	{
		String gameId = request.getParameter("gameId");
		String shuiweiOffset = request.getParameter("shuiweiOffset");
		String daxiaoOffset = request.getParameter("daxiaoOffset");
		String hasDaxiao = request.getParameter("hasDaxiao");

		SearchBean bean = new SearchBean();
		bean.setGameId(Long.parseLong(gameId));
		bean.setHasDaxiao(Integer.parseInt(hasDaxiao));
		bean.setBigOffset(Float.parseFloat(daxiaoOffset));
		bean.setShuiweiOffset(Float.parseFloat(shuiweiOffset));
		StringBuffer sb = new StringBuffer();
		GameResult r = killerService.getGameResultByGameId(Long.parseLong(gameId));
		Set<GameDetail> set = r.getGameDetails();
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("公司");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("类型");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队水位");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("让球盘口");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队水位");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主胜赔率");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("平局赔率");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客胜赔率");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大球水位");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小盘口");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("小球水位");
		sb.append("</td>");
		sb.append("</tr>");

		for (GameDetail detail : set)
		{
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(detail.getCompanyName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("初盘");
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanHostShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanVisitShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanHostOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanDrawOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanVisitOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanBigShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanDaxiaoPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanSmallShuiwei());
			sb.append("</td>");
			sb.append("</tr>");
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(detail.getCompanyName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("终盘");
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiHostShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiVisitShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiHostOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiDrawOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiVisitOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiBigShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiDaxiaoPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiSmallShuiwei());
			sb.append("</td>");
			sb.append("</tr>");
		}
		List<GameResult> result = killerService.SearchGameResult(bean);

		if (result == null)
			return null;
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("比赛编号");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("联赛");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("比赛日期");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("半场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("全场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("盘口结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小结果");
		sb.append("</td>");
		sb.append("</tr>");
		for (int i = 0; i < result.size(); i++)
		{
			GameResult gameResult = result.get(i);
			sb.append("<tr bgcolor='#f47983'>");
			sb.append("<td>");
			sb.append(gameResult.getGameId());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getLeagueName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getHostTeam());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getVisitTeam());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getGameTime().toLocaleString());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getHalfScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getFullScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getPankouResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getDaxiaoResult());
			sb.append("</td>");
			sb.append("</tr>");
			Set<GameDetail> set1 = gameResult.getGameDetails();
			sb.append("<tr>");
			sb.append("<td>");
			sb.append("公司");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("类型");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("主队水位");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("让球盘口");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("客队水位");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("主胜赔率");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("平局赔率");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("客胜赔率");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("大球水位");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("大小盘口");
			sb.append("</td>");
			sb.append("<td>");
			sb.append("小球水位");
			sb.append("</td>");
			sb.append("</tr>");

			for (GameDetail detail : set1)
			{
				sb.append("<tr>");
				sb.append("<td>");
				sb.append(detail.getCompanyName());
				sb.append("</td>");
				sb.append("<td>");
				sb.append("初盘");
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanHostShuiwei());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanPankou());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanVisitShuiwei());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanHostOdds());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanDrawOdds());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanVisitOdds());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanBigShuiwei());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanDaxiaoPankou());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getChupanSmallShuiwei());
				sb.append("</td>");
				sb.append("</tr>");
				sb.append("<tr>");
				sb.append("<td>");
				sb.append(detail.getCompanyName());
				sb.append("</td>");
				sb.append("<td>");
				sb.append("终盘");
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiHostShuiwei());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiPankou());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiVisitShuiwei());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiHostOdds());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiDrawOdds());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiVisitOdds());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiBigShuiwei());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiDaxiaoPankou());
				sb.append("</td>");
				sb.append("<td>");
				sb.append(detail.getJishiSmallShuiwei());
				sb.append("</td>");
				sb.append("</tr>");
			}
		}
		return sb.toString();
	}

	@RequestMapping(params = "method=getGameInfo")
	public @ResponseBody
	GameResult getGameInfo(HttpServletRequest request)
	{
		String gameId = request.getParameter("gameId");
		if (StringUtil.isNotNull(gameId))
		{
			GameResult result = killerService.getGameResultByGameId(Long.parseLong(gameId));
			return result;
		}
		else
		{
			logger.error("Game ID is null");
			return null;
		}
	}

	private boolean isChecked(String str)
	{
		if (StringUtil.isNotNull(str))
			return str.trim().toUpperCase().equals(
				"CHECKED");
		return false;
	}

	@RequestMapping(params = "method=analysisGame")
	public @ResponseBody
	String analysisGame(HttpServletRequest request)
	{
		long gameId = Long.parseLong(request.getParameter("gameId"));
		boolean isSbShuiwei = isChecked(request.getParameter("isSbShuiwei"));
		boolean isSbOdds = isChecked(request.getParameter("isSbOdds"));
		boolean isSbDaxiao = isChecked(request.getParameter("isSbDaxiao"));
		boolean isBetShuiwei = isChecked(request.getParameter("isBetShuiwei"));
		boolean isBetOdds = isChecked(request.getParameter("isBetOdds"));
		boolean isBetDaxiao = isChecked(request.getParameter("isBetDaxiao"));
		boolean isAocaiShuiwei = isChecked(request.getParameter("isAocaiShuiwei"));
		boolean isAocaiOdds = isChecked(request.getParameter("isAocaiOdds"));
		boolean isAocaiDaxiao = isChecked(request.getParameter("isAocaiDaxiao"));
		double shuiweiOffset = Double.parseDouble(request.getParameter("shuiweiOffset"));
		double oddsOffset = Double.parseDouble(request.getParameter("oddsOffset"));
		double daxiaoOffset = Double.parseDouble(request.getParameter("daxiaoOffset"));

		GameResult gameResult = killerService.getGameResultByGameId(gameId);

		if (gameResult == null)
			return null;

		SearchBean bean = new SearchBean();
		// bean.setGameResult(gameResult);
		// bean.setShuiweiOffset(shuiweiOffset);
		// bean.setOddsOffset(oddsOffset);
		// bean.setBigOffset(daxiaoOffset);
		//
		// if(isSbShuiwei || isSbOdds || isSbDaxiao){
		// CompanyBean companyBean = new CompanyBean(ICompanyName.COMPANY_SB);
		// companyBean.setDaxiao(isSbDaxiao);
		// companyBean.setOdds(isSbOdds);
		// companyBean.setRangQiu(isSbShuiwei);
		// bean.addCompanyBean(companyBean);
		// }
		//
		// if(isBetShuiwei || isBetOdds || isBetDaxiao){
		// CompanyBean companyBean = new
		// CompanyBean(ICompanyName.COMPANY_BET365);
		// companyBean.setDaxiao(isBetDaxiao);
		// companyBean.setOdds(isBetOdds);
		// companyBean.setRangQiu(isBetShuiwei);
		// bean.addCompanyBean(companyBean);
		// }
		//
		// if(isAocaiShuiwei || isAocaiOdds || isAocaiDaxiao){
		// CompanyBean companyBean = new
		// CompanyBean(ICompanyName.COMPANY_AOCAI);
		// companyBean.setDaxiao(isAocaiDaxiao);
		// companyBean.setOdds(isAocaiOdds);
		// companyBean.setRangQiu(isAocaiShuiwei);
		// bean.addCompanyBean(companyBean);
		// }

		List<GameResult> results = killerService.SearchGameResult(bean);
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < results.size(); i++)
		{
			GameResult gr = results.get(i);
			String dataString = generateData(
				gr, false);
			sb.append(dataString);
		}
		return sb.toString();
	}

	/**
	 * <li id="123456" onClick="toAnalysisAction(123456)">
	 * <table>
	 * <tr>
	 * <td rowspan="2" class="tdStar">
	 * <img src="jquery-mobile/images/star1@2x.png" class="star"></td>
	 * <td rowspan="2" class="tdStatus">δ����</td>
	 * <td class="tdGame" colspan="2">������</td>
	 * <td class="tdTime">15:30</td>
	 * <td class="tdResult" rowspan="2">2:0</td>
	 * <td rowspan="2" class="tdMore"><img
	 * src="jquery-mobile/images/more@2x.png" class="more"></td>
	 * </tr>
	 * <tr>
	 * <td class="tdHostTeam">�¶��з�</td>
	 * <td>:</td>
	 * <td class="tdVisitTeam">������</td>
	 * </tr>
	 * </table>
	 * </li>
	 */
	private String generateData(GameResult gameResult, boolean isAnalyis)
	{
		long gameId = gameResult.getGameId();
		String hostTeam = gameResult.getHostTeam();
		String visitTeam = gameResult.getVisitTeam();
		String fullScore = gameResult.getFullScore();
		String gameType = gameResult.getLeagueName();
		String gameTime = DateUtil.convertTimeStampToString(gameResult.getGameTime());
		StringBuffer sb = new StringBuffer();
		String funName = isAnalyis ? "showGameData" : "showDetail";
		sb.append("<li id='" + gameId + "' onTouchEnd='" + funName + "(" + gameId + ")'>");
		sb.append("<table>");
		sb.append("<tr>");
		sb.append("<td rowspan='2'  class='tdStar'>");
		sb.append("<img src='jquery-mobile/images/star1@2x.png' class='star'>");
		sb.append("</td>");
		sb.append("<td rowspan='2' class='tdStatus'>");
		sb.append("�ѿ���"); // TODO
		sb.append("</td>");
		sb.append("<td class='tdGame' colspan='2'>");
		sb.append(gameType.trim());
		sb.append("</td>");
		sb.append("<td class='tdTime'>");
		sb.append(gameTime);
		sb.append("</td>");
		sb.append("<td class='tdResult' rowspan='2'>");
		sb.append(fullScore);
		sb.append("</td>");
		sb.append("<td rowspan='2' class='tdMore'>");
		sb.append("<img src='jquery-mobile/images/more@2x.png' class='more'>");
		sb.append("</td>");
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<td class='tdHostTeam'>");
		sb.append(hostTeam.trim());
		sb.append("</td>");
		sb.append("<td>");
		sb.append(":");
		sb.append("</td>");
		sb.append("<td class='tdVisitTeam'>");
		sb.append(visitTeam.trim());
		sb.append("</td>");
		sb.append("</tr>");
		sb.append("</table>");
		sb.append("</li>");
		return sb.toString();
	}

	@RequestMapping(params = "method=getDetail")
	public @ResponseBody
	String getDetail(HttpServletRequest request)
	{
		StringBuffer sb = new StringBuffer();
		long gameId = Long.parseLong(request.getParameter("gameId"));
		GameResult gameResult = killerService.getGameResultByGameId(gameId);
		Set<GameDetail> set1 = gameResult.getGameDetails();
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("公司");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("类型");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队水位");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("让球盘口");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队水位");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主胜赔率");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("平局赔率");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客胜赔率");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大球水位");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小盘口");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("小球水位");
		sb.append("</td>");
		sb.append("</tr>");

		for (GameDetail detail : set1)
		{
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(detail.getCompanyName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("初盘");
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanHostShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanVisitShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanHostOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanDrawOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanVisitOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanBigShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanDaxiaoPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getChupanSmallShuiwei());
			sb.append("</td>");
			sb.append("</tr>");
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(detail.getCompanyName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("终盘");
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiHostShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiVisitShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiHostOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiDrawOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiVisitOdds());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiBigShuiwei());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiDaxiaoPankou());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(detail.getJishiSmallShuiwei());
			sb.append("</td>");
			sb.append("</tr>");
		}
		return sb.toString();
	}

	@RequestMapping(params = "method=analysis")
	public @ResponseBody
	String analysis(HttpServletRequest request)
	{
		long gameId = Long.parseLong(request.getParameter("gameId"));
		SearchBean bean = new SearchBean();
		String shuiweiOffset = request.getParameter("shuiweiOffset");
		String daxiaoOffset = request.getParameter("daxiaoOffset");
		String hasDaxiao = request.getParameter("hasDaxiao");
		bean.setHasDaxiao(Integer.parseInt(hasDaxiao));
		bean.setShuiweiOffset(Float.parseFloat(shuiweiOffset));
		bean.setBigOffset(Float.parseFloat(daxiaoOffset));
		bean.setGameId(gameId);
		List<GameResult> analysisResult = killerService.SearchGameResult(bean);
		return killerService.getAnalysisResult(analysisResult, false);
	}
	
	@RequestMapping(params = "method=todayDaqiuGames")
	public @ResponseBody
	String todayDaqiuGames()
	{
		List<GameResult> result = killerService.searchDaqiuGameResult();
		StringBuffer sb = new StringBuffer();
		if (result == null)
			return null;
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("比赛日期");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("联赛");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("比赛编号");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("半场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("全场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("盘口结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("分析");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("凯勒分析结果");
		sb.append("</td>");
		sb.append("</tr>");
		for (int i = 0; i < result.size(); i++)
		{
			GameResult gameResult = result.get(i);
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(gameResult.getGameTime().toLocaleString());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getLeagueName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getHostTeam());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getVisitTeam());
			sb.append("</td>");
			sb.append("<td><a href='analysis.jsp?gameID=" + gameResult.getGameId() + "'>");
			sb.append(gameResult.getGameId());
			sb.append("</a></td>");
			sb.append("<td>");
			sb.append(gameResult.getHalfScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getFullScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getPankouResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getDaxiaoResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("<input type='button' value='分析' onclick='analysis(" + gameResult.getGameId()
				+ ")'");
			sb.append("</td>");
			sb.append("<td id=killerResult" + gameResult.getGameId() + ">");
			sb.append("</td>");
			sb.append("</tr>");
		}
		return sb.toString();
	}
	
	@RequestMapping(params = "method=analysisAllDaqiu")
	public @ResponseBody
	String analysisAllDaqiu(HttpServletRequest request)
	{
		List<GameResult> result = killerService.searchDaqiuGameResult();
		StringBuffer sb = new StringBuffer();
		if (result == null)
			return null;
		sb.append("<tr>");
		sb.append("<td>");
		sb.append("比赛日期");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("联赛");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("主队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("客队");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("比赛编号");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("半场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("全场比分");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("盘口结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("大小结果");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("分析");
		sb.append("</td>");
		sb.append("<td>");
		sb.append("凯勒分析结果");
		sb.append("</td>");
		sb.append("</tr>");
		for (int i = 0; i < result.size(); i++)
		{
			GameResult gameResult = result.get(i);
			long gameId = gameResult.getGameId();
			SearchBean bean = new SearchBean();
			String shuiweiOffset = request.getParameter("shuiweiOffset");
			String daxiaoOffset = request.getParameter("daxiaoOffset");
			String hasDaxiao = request.getParameter("hasDaxiao");
			bean.setHasDaxiao(Integer.parseInt(hasDaxiao));
			bean.setBigOffset(Float.parseFloat(daxiaoOffset));
			bean.setShuiweiOffset(Float.parseFloat(shuiweiOffset));
			bean.setGameId(gameId);
			List<GameResult> analysisResult = killerService.SearchGameResult(bean);
			String killerResult = killerService.getAnalysisResult(analysisResult, false);
			sb.append("<tr>");
			sb.append("<td>");
			sb.append(gameResult.getGameTime().toLocaleString());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getLeagueName());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getHostTeam());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getVisitTeam());
			sb.append("</td>");
			sb.append("<td><a href='analysis.jsp?gameID=" + gameResult.getGameId() + "'>");
			sb.append(gameResult.getGameId());
			sb.append("</a></td>");
			sb.append("<td>");
			sb.append(gameResult.getHalfScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getFullScore());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getPankouResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append(gameResult.getDaxiaoResult());
			sb.append("</td>");
			sb.append("<td>");
			sb.append("<input type='button' value='分析' onclick='analysis(" + gameResult.getGameId()
				+ ")'");
			sb.append("</td>");
			sb.append("<td>");
			sb.append(killerResult);
			sb.append("</td>");
			sb.append("</tr>");
		}
		return sb.toString();
	}
}
